#this program forms a list of the Gamma Knife shot times and shot dose rates for all the voxels in the dose array #and writes this list to a text file import os #imports the operating system module, needed for file and directory functions import numpy as np #imports the NumPy scientific computing library and makes np shorthand for numpy os.chdir("/Users/Documents/pydicom-0.9.7") #sets the directory path import dicom #imports the pydicom package shot1=dicom.read_file("shot1.dcm") #reads in the shot1 dicom rtdose file shot2=dicom.read_file("shot2.dcm") #reads in the shot2 dicom rtdose file shot3=dicom.read_file("shot3.dcm") #reads in the shot3 dicom rtdose file shot4=dicom.read_file("shot4.dcm") #reads in the shot4 dicom rtdose file shot5=dicom.read_file("shot5.dcm") #reads in the shot5 dicom rtdose file shot6=dicom.read_file("shot6.dcm") #reads in the shot6 dicom rtdose file shot_times=[9.03, 7.78, 8.24, 4.90, 4.02, 1.88] #list of the shot times in minutes shot1_dosescalingfactor=float(shot1.DoseGridScaling) #shot 1 dose scaling factor for converting dose array integer to Gy shot2_dosescalingfactor=float(shot2.DoseGridScaling) #shot 2 dose scaling factor for converting dose array integer to Gy shot3_dosescalingfactor=float(shot3.DoseGridScaling) #shot 3 dose scaling factor for converting dose array integer to Gy shot4_dosescalingfactor=float(shot4.DoseGridScaling) #shot 4 dose scaling factor for converting dose array integer to Gy shot5_dosescalingfactor=float(shot5.DoseGridScaling) #shot 5 dose scaling factor for converting dose array integer to Gy shot6_dosescalingfactor=float(shot6.DoseGridScaling) #shot 6 dose scaling factor for converting dose array integer to Gy shot1_time=shot_times[0] #shot 1 time shot2_time=shot_times[1] #shot 2 time shot3_time=shot_times[2] #shot 3 time shot4_time=shot_times[3] #shot 4 time shot5_time=shot_times[4] #shot 5 time shot6_time=shot_times[5] #shot 6 time textfile=open("shot_times_and_doserates.txt","w") #creates and opens a text file in write mode #the for loop below iterates through the voxels in the dose array and obtains the dose rates for each shot #the shot times and the shot dose rates are then placed in a list and written to a text file for a in range(0,11): for b in range(0,10): for c in range(0,9): shot1_doserate=shot1.pixel_array[a,b,c]*shot1_dosescalingfactor/shot1_time #shot1 doserate in voxel [a,b,c] shot2_doserate=shot2.pixel_array[a,b,c]*shot2_dosescalingfactor/shot2_time #shot2 doserate in voxel [a,b,c] shot3_doserate=shot3.pixel_array[a,b,c]*shot3_dosescalingfactor/shot3_time #shot3 doserate in voxel [a,b,c] shot4_doserate=shot4.pixel_array[a,b,c]*shot4_dosescalingfactor/shot4_time #shot4 doserate in voxel [a,b,c] shot5_doserate=shot5.pixel_array[a,b,c]*shot5_dosescalingfactor/shot5_time #shot5 doserate in voxel [a,b,c] shot6_doserate=shot6.pixel_array[a,b,c]*shot6_dosescalingfactor/shot6_time #shot6 doserate in voxel [a,b,c] #the line below forms a list of the shot dose rates shot_doserates=[shot1_doserate,shot2_doserate,shot3_doserate,shot4_doserate,shot5_doserate,shot6_doserate] #the line below puts the shot times and shot dose rates together in an array shot_times_and_shot_doserates=np.array([shot_times,shot_doserates]).transpose() #the line below converts the shot_times_and_shot_doserates array into a list shot_times_and_shot_doserates_list=shot_times_and_shot_doserates.tolist() textfile=open("shot_times_and_doserates.txt","a") #opens the text file in append mode print >>textfile, shot_times_and_shot_doserates_list #writes the shot times and dose rates to the text file textfile.close() #closes the text file